package com.haiertvbic.tvnow.adapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.haiertvbic.tvnow.R;

public class FunctionAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<String> fName = new ArrayList<String>();
	private ArrayList<Boolean> fStatus = new ArrayList<Boolean>();

	public FunctionAdapter(HashMap<String, Boolean> function, Context context) {
		this.context = context;
		for (Entry<String, Boolean> m : function.entrySet()) {
			fName.add(m.getKey());
			fStatus.add(m.getValue());
		}
	}

	public FunctionAdapter(ArrayList<String> fName, ArrayList<Boolean> fStatus,
			Context context) {
		this.context = context;
		this.fName = fName;
		this.fStatus = fStatus;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return fName.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	public class FunctionHodler {
		public TextView fName;
		public ImageView fStatus;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		FunctionHodler hodler = new FunctionHodler();
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.layout_function_item,
					null);
			hodler.fName = (TextView) convertView
					.findViewById(R.id.function_name);
			hodler.fStatus = (ImageView) convertView
					.findViewById(R.id.situation);
			convertView.setTag(hodler);
		} else {
			hodler = (FunctionHodler) convertView.getTag();
		}
		hodler.fName.setText(fName.get(position));
		if (fStatus.get(position)) {
			hodler.fStatus.setImageResource(R.drawable.function_open);
		} else {
			hodler.fStatus.setImageResource(R.drawable.function_close);
		}
		return convertView;
	}

}
